package com.main.ok.guahaouser;

import java.net.MalformedURLException;
import java.util.List;

import com.caucho.hessian.client.HessianConnectionFactory;
import com.caucho.hessian.client.HessianProxyFactory;
import com.caucho.hessian.client.HessianURLConnectionFactory;
import com.greenline.guahao.user.model.bo.UserAppDeviceBO;
import com.greenline.guahao.user.service.UserService;
import com.greenline.guahao.user.service.dto.UserDTO;
import com.greenline.guahao.user.service.response.UserResponse;
import com.greenline.guahao.user.service.share.UserAppDeviceService;
import com.greenline.hrs.util.core.bo.response.Response;

public class TestUpdateUser {
    //    static String url = "http://10.10.120.157:8100/user/service/userService";
    static String url = "http://192.168.1.29:3000/user/service/userService";//查询用户详情
    static String device_url = "http://192.168.1.29:3000/user/service/userAppDeviceService";//查询user_app_device 表用户在线
    static HessianProxyFactory factory = new HessianProxyFactory();
    static UserService service = null;
    static UserAppDeviceService userAppDeviceService = null;

    static {
        try {

            service = (UserService) factory.create(UserService.class, url);
            userAppDeviceService = (UserAppDeviceService) factory.create(UserAppDeviceService.class, device_url);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }

    public static UserService getUserService() {
//        HessianConnectionFactory hessianConnectionFactory = new ForwardHessianConnectionFactory();
//        hessianConnectionFactory.
        HessianProxyWtihContextFactory hessianProxyWtihContextFactory = new HessianProxyWtihContextFactory();
        hessianProxyWtihContextFactory.putContext("sourceId", "0001");
        UserService userService = null;
        try {
            userService = (UserService) hessianProxyWtihContextFactory.create(UserService.class, url);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        return userService;
    }


    public static void main(String[] args) {
        try {
//            testUpdateUser();
            queryUser();
//            testOnlineUser();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public static void testOnlineUser() {
        UserAppDeviceBO appDeviceBO = new UserAppDeviceBO();
        appDeviceBO.setUid(5561945l);
        Response<List<UserAppDeviceBO>> list = userAppDeviceService.list(appDeviceBO);
        List<UserAppDeviceBO> data = list.getData();
        for (UserAppDeviceBO bo : data) {
            System.out.println(bo.getAppId() + "--" + bo.getUid() + "--" + bo.getIsOnline());
        }
    }

    public static void testUpdateUser() throws Exception {

        UserDTO userDTO = new UserDTO();
//         userDTO.setMobile("13968180846");
//         userDTO.setUserId(11439646);
//         userDTO.setEmail("zuoshuai@guahao.com");
//         userDTO.setUserName("zuoshuai");

//        userDTO.setMobile("13968180846");
//        userDTO.setUserId(11439624);
//        userDTO.setEmail("609520083@qq.com");
//        userDTO.setUserName("sandbox");

//        userDTO.setMobile("13291872722");
//        userDTO.setUserId(11791823);
//        userDTO.setEmail("609520083@qq.com");
//        userDTO.setUserName("sandbox");
        //生产
        userDTO.setMobile("13291872722");
        userDTO.setUserId(13376089);
        userDTO.setEmail("609520083@qq.com");
        userDTO.setUserName("左帅");

        UserResponse<UserDTO> response = service.updateUser(userDTO);
        System.out.println(response.getCode() + "-----" + response.getDesc() + "--" + response.getData());

    }

    public static void queryUser() {
        UserDTO user = new UserDTO();
        user.setMobile("13811112222");
        UserResponse<List<UserDTO>> s = getUserService().queryUser(user);
        List<UserDTO> data = s.getData();
        for (UserDTO res : data) {
            System.out.println(res.getUserName() + "--" + res.getMobile() + "--" + res.getEmail() + "--" + res.getCertNo() + "--" + res.getUserId()+"--"+res.getReg_type());
        }
    }
}
